import { computed } from "vue";

export const useComputed = (fn: any) => {
  const cache = new Map();
  const getCache = (args: any[]) => {
    return cache.get(JSON.stringify(args));
  };
  return (...args: any[]) => {
    const cacheResult = getCache(args);
    if (cacheResult) {
      return cacheResult;
    }
    const result = computed(() => fn(...args));
    cache.set(JSON.stringify(args), result.value);
    return result.value;
  };
};
